package shapewar.engine.presenter;

import java.util.Enumeration;
import java.util.Iterator;

import shapewar.engine.calc.Pos;
import shapewar.engine.intefac.IHittable;
import shapewar.engine.intefac.IRegisterable;
import shapewar.engine.intefac.ITank;
import shapewar.engine.intefac.IView;
import shapewar.engine.model.abst.ModelAdapter;
import shapewar.view.effect.EffectView;
import shapewar.view.indvidul.HandlerView;
import shapewar.view.indvidul.MapView;
import shapewar.view.indvidul.PointView;
import shapewar.view.indvidul.VisibleAreaView;
import shapewar.view.indvidul.WallView;
import shapewar.view.intefac.IMyView;
import shapewar.view.myview.MyButton;
import shapewar.view.myview.MyView;
import shapewar.view.tank.BulletView;
import shapewar.view.tank.ProtectorView;
import shapewar.view.tank.TankView;

public class ViewBridge {
	private Presenter pst;
	
	public ViewBridge(Presenter pst) {
		this.pst = pst;
	}
	
	public HandlerView createHandlerView(IView shape){
		return new HandlerView(pst, shape.getModel());
	}
	
	public MyView createMapView(IView shape) {
		return new MapView(pst,shape.getModel());
	}
	
	public PointView createPointView(IView shape){
		return new PointView(pst);
	}

	public MyView createVisibleAreaView(IView shape) {
		return new VisibleAreaView(pst,shape.getModel());
	}
	
	public TankView createTankView(IView shape) {
		return new TankView(pst, shape.getModel());
	}
	
	public ProtectorView createProtectorView(IView shape){
		return new ProtectorView(pst,shape.getModel());
	}
	
	public MyView createBulletView(IView shape){
		return new BulletView(pst,shape.getModel());
	}

	public MyView createWallView(IView shape) {
		return new WallView(pst,shape.getModel());
	}
	
	public MyView createView(IView shape){
		return new MyView(pst,shape.getModel());
	}
	
	//getView
	public MyView getView(IView shape){
		return shape.getView();
	}
	//AddView RemoveView
	public void addView(MyView view) {
		pst.ect.frame.addView(view);
	}
	public void removeView(MyView view) {
		pst.ect.frame.removeView(view);
	}
	
	//Create Effect
	public void createFlashEffect(IView shape){
		EffectView effect_view = new EffectView(pst, shape.getModel());
		effect_view.createFlashEffect(new Pos(shape.getModel()._x,shape.getModel()._y));
	}
	public void createBulletDieEffect(IView shape){
		EffectView effect_view = new EffectView(pst, shape.getModel());
		effect_view.createBulletDieEffect(new Pos(shape.getModel()._x,shape.getModel()._y));
	}
	//Update
	
	public void invalidate(IView shape) {
		shape.getView().invalidate();
	}
	
	public void bringToFront(IView shape) {
		shape.getView().bringToFront();
	}
	
	public void invalidateAll() {
//		Iterator<IRegisterable> it = pst.ect.tr_view.iterator();
//		try {
//			while(it.hasNext()){
//				IMyView view = ((IView)it.next()).getView();
//				view.invalidate();
//			}
//		} catch (Exception e) {
//			System.out.println("ERR");
//		}
		Enumeration<IRegisterable> es = pst.ect.tr_view.elements();
		while(es.hasMoreElements()){
			IMyView view = ((IView)es.nextElement()).getView();
			view.invalidate();
		}
	}
	
}
